<?php include dirname(__FILE__).'/common/header.php'; ?>

<?php include dirname(__FILE__).'/common/menu.php'; ?>

var attr = {};
	
	list.grid = new ZM.GridPanel({
		url: list.baseUrl + 'framework/getFrameworkFileList',
		history:'framework_file_id',
		onlyShow:true,
		region:'center',
		tbar:[{
			text:'新建',
			cls:'btn-show',
			iconCls:'icon-create',
			hidden: !Ext.permission['framework/createFrameworkFile'.toLowerCase()],
			handler:function() {
				var frm = new ZM.FormPanel({
					url: list.baseUrl + 'framework/createFrameworkFile',
					keySubmit:true,
					success:function(res) {
						ZM.bo.msg('成功!',res.detail);
						list.grid.store.reload();
						win.close();
					},
					items:[{
						fieldLabel:'名称',
						name:'framework_file_name',
						allowBlank:false
					}]
				});
				var win = new ZM.PopUp({
					title:'新建框架',
					type:'s',
					items:frm
				});
				win.show();
			}
		}],
		bbar:null,
		saveSortCfg:{
			url: list.baseUrl + 'framework/sortFrameworkFile',
			name:'framework_file_ids',
			dataIndex:'framework_file_id',
			hidden: !Ext.permission['framework/sortFrameworkFile'.toLowerCase()],
		},
		columns:[
			{header:'ID',dataIndex:'framework_file_id',hidden:true},
			{header:'名称',dataIndex:'framework_file_name',width:140},
			{header:'最后修改时间',dataIndex:'framework_file_time_lastmodified',width:160},
			{header:'状态',dataIndex:'framework_file_status',width:60,renderer:ZM.status},
			{header:'移动',dataIndex:'move',xtype:'movecolumn',hidden:!Ext.permission['framework/sortFrameworkFile'.toLowerCase()]},
			{header:'操作',dataIndex:'',renderer:function(val,m,r) {
					var str = '';
					str += Ext.rd('编辑','fireEditFramework',r,'framework/editFrameworkFile');
					if(r.json.framework_file_status == 1) {
						str += Ext.rd('禁用','fireDisableFramework',r,'framework/disableFrameworkFile');
					} else {
						str += Ext.rd('启用','fireEnableFramework',r,'framework/enableFrameworkFile');
					}
					str += '<a href="#" id="_'+r.id+'" title="fireViewFramework" >[预览]</a>';
					return str;
				}
			}
		]
	});
	
	list.grid.fireEditFramework = function(r) {
		var r = r.json;
		var content = r.framework_file_content;
		var toClose = false;
		var frm = new ZM.FormPanel({
			url: list.baseUrl + 'framework/editFrameworkFile',
			tbar:[{
				text:'保存',
				cls:'btn-show',
				iconCls:'icon-save',
				hidden:!Ext.permission['framework/editFrameworkFile'.toLowerCase()],
				handler:function(){
					ZM.submitForm(frm);
				}
			}],
			buttons:null,
			focusField:false,
			params:{framework_file_id:r.framework_file_id
					,framework_file_time_lastmodified:r.framework_file_time_lastmodified},
			success:function(res) {
				ZM.bo.msg('成功!',res.detail);
				list.grid.store.reload();
				content = Ext.getCmp('field_framework_file_content').getValue();
				frm.params.framework_file_time_lastmodified = res.addon.framework_file_time_lastmodified;
			},
			items:[{
				fieldLabel:'名称',
				name:'framework_file_name',
				value:r.framework_file_name,
				allowBlank:false
			},{
				xtype:'textarea',
				fieldLabel:'内容',
				name:'framework_file_content',
				id:'field_framework_file_content',
				value:r.framework_file_content,
				plugins:[new ZM.tabKey()],
				width:800,
				height:360
			}]
		});
		var win = new ZM.PopUp({
			title:'编辑框架['+r.framework_file_name+']',
			type:'l',
			items:frm,
			listeners:{
				beforeclose:function(w) {
					if(toClose) return;
					if(Ext.getCmp('field_framework_file_content').getValue() != content) {
						Ext.Msg.confirm('确认?','未保存改变的内容，您确定要关闭吗?',function(btn) {
							if(btn == 'yes') {
								toClose = true;
								win.close();
							}
						});
						return false;
					}
				}
			}
		});
		win.show();
	}
	
	list.grid.fireDisableFramework = function(r) {
		var r = r.json;
		Ext.Msg.confirm('确认?','确定要禁用框架['+r.framework_file_name+']?',function(btn) {
			if(btn == 'yes') {
				list.grid.getEl().mask('正在禁用中...','x-mask-loading');
				ZM.ajax({
					url:list.baseUrl + 'framework/disableFrameworkFile',
					params:{framework_file_id:r.framework_file_id},
					success:function(res) {
						ZM.bo.msg('成功!',res.detail);
						list.grid.getEl().unmask();
						list.grid.store.reload();
					},
					failure:function(res) {
						ZM.bo.msg('失败!',res.detail);
						list.grid.getEl().unmask();
					}
				});
			}
		});
	}
	
	list.grid.fireEnableFramework = function(r) {
		var r = r.json;
		Ext.Msg.confirm('确认?','确定要启用框架['+r.framework_file_name+']?',function(btn) {
			if(btn == 'yes') {
				list.grid.getEl().mask('正在禁用中...','x-mask-loading');
				ZM.ajax({
					url:list.baseUrl + 'framework/enableFrameworkFile',
					params:{framework_file_id:r.framework_file_id},
					success:function(res) {
						ZM.bo.msg('成功!',res.detail);
						list.grid.getEl().unmask();
						list.grid.store.reload();
					},
					failure:function(res) {
						ZM.bo.msg('失败!',res.detail);
						list.grid.getEl().unmask();
					}
				});
			}
		});
	}
	
	list.grid.fireViewFramework = function(r) {
		Ext.cssContent = r.json.framework_file_content;
		list.detail.show().ownerCt.doLayout();
		 list.detail.getEl().mask('数据加载中...', 'x-mask-loading');
		document.getElementById('iframe-frameWidget').src = '/application/views/iframes/css-view.html';
		document.getElementById('iframe-frameWidget').onload = function(){list.detail.getEl().unmask();}
	}

	list.detail = new ZM.detailPanel({
		items:new ZM.IFRAME({
			id : 'frameWidget',
			url : 'about:blank'
		})
	});
	
<?php include dirname(__FILE__).'/common/layout.php'; ?>
list.grid.store.load();
<?php include dirname(__FILE__).'/common/footer.php'; ?>